package college;


import java.util.Arrays;
import java.util.List;

/**
 * Class will handle the mathematical statistic functions that the project uses.
 * @author Group11
 *
 */

public class Statistics 
{

	/**
	 * Mathematical median.
	 * @param l - A list of long variable for the median to be used.
	 * @return long
	 */
	public static long median(long[] l)
	  {
	    Arrays.sort(l);
	    int middle = l.length / 2;
	    if (l.length % 2 == 0)
	    {
	      long left = l[middle - 1];
	      long right = l[middle];
	      return (left + right) / 2;
	    }
	    else
	    {
	      return l[middle];
	    }
	  }
	
	/**
	 * Functions gets a list of integers and returns their summary.
	 * @param a A list of Integer.
	 * @return int sum.
	 */
	  public int sum (List<Integer> a)
	  {
	        if (a.size() > 0) {
	            int sum = 0;
	 
	            for (Integer i : a) {
	                sum += i;
	            }
	            return sum;
	        }
	        return 0;
	    }
	
	  /**
	   * Assisting function.
	   * @param a
	   * @return
	   */
	public double mean (List<Integer> a)
	{
        int sum = sum(a);
        double mean = 0;
        mean = sum / (a.size() * 1.0);
        return mean;
	}
	
	
	public double sd (List<Integer> a)
	{
        int sum = 0;
        double mean = mean(a);
 
        for (Integer i : a)
            sum += Math.pow((i - mean), 2);
        return Math.sqrt( sum / ( a.size() - 1 ) ); // sample
    }
	
	
}
